package com.ds.dsm.view.config.gallery;

import com.ds.common.JDSException;
import com.ds.config.ResultModel;
import com.ds.dsm.aggregation.module.ModuleWinGroup;
import com.ds.esd.custom.annotation.CustomAnnotation;
import com.ds.esd.custom.annotation.FormViewAnnotation;
import com.ds.esd.custom.api.annotation.APIEventAnnotation;
import com.ds.esd.custom.buttonviews.annotation.ButtonViewsAnnotation;
import com.ds.esd.custom.gallery.CustomGalleryDataBean;
import com.ds.esd.custom.module.annotation.DynLoadAnnotation;
import com.ds.esd.custom.module.annotation.ModuleAnnotation;
import com.ds.esd.custom.nav.annotation.NavGroupViewAnnotation;
import com.ds.esd.dsm.DSMFactory;
import com.ds.esd.dsm.view.ViewEntityConfig;
import com.ds.esd.tool.ui.component.tab.SideBarStatusType;
import com.ds.esd.tool.ui.enums.BarLocationType;
import com.ds.esd.tool.ui.enums.Dock;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(path = "/dsm/view/config/gallery/")
@ButtonViewsAnnotation(barLocation = BarLocationType.top, sideBarStatus = SideBarStatusType.expand, barSize = "3em")
public class GalleryDataGroup {


    @CustomAnnotation(hidden = true, pid = true)
    String viewInstId;

    @CustomAnnotation(hidden = true, pid = true)
    String sourceClassName;


    @CustomAnnotation(hidden = true, uid = true)
    String methodName;

    public GalleryDataGroup() {

    }


    @RequestMapping(method = RequestMethod.POST, value = "GalleryDataView")
    @FormViewAnnotation(reSetUrl = "clearGalleryData", saveUrl = "updateGalleryData")
    @ModuleAnnotation(imageClass = "spafont spa-icon-values", caption = "数据信息")
    @CustomAnnotation(dock = Dock.fill)
    @APIEventAnnotation(autoRun = true)
    @ResponseBody
    public ResultModel<GalleryDataView> getGalleryDataView(String sourceClassName, String methodName, String domainId, String viewInstId) {

        ResultModel<GalleryDataView> result = new ResultModel<GalleryDataView>();
        try {
            ViewEntityConfig tableConfig = DSMFactory.getInstance().getViewManager().getViewEntityConfig(sourceClassName, viewInstId);
            CustomGalleryDataBean galleryViewBean = (CustomGalleryDataBean) tableConfig.getSourceConfig().getMethodByName(methodName).getDataBean();
            result.setData(new GalleryDataView(galleryViewBean));
        } catch (JDSException e) {
            e.printStackTrace();
        }


        return result;
    }

    @RequestMapping(method = RequestMethod.POST, value = "GalleryWinView")
    @DynLoadAnnotation
    @NavGroupViewAnnotation(reSetUrl = "clearGalleryData",
            saveUrl = "updateGalleryWinData")

    @ModuleAnnotation(imageClass = "spafont spa-icon-c-dialog", caption = "窗体配置", dock = Dock.fill)
    @APIEventAnnotation(autoRun = true)
    @ResponseBody
    public ResultModel<ModuleWinGroup> getGalleryWinView(String sourceClassName, String viewInstId) {

        ResultModel<ModuleWinGroup> result = new ResultModel<ModuleWinGroup>();
        return result;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public String getViewInstId() {
        return viewInstId;
    }

    public void setViewInstId(String viewInstId) {
        this.viewInstId = viewInstId;
    }

    public String getSourceClassName() {
        return sourceClassName;
    }

    public void setSourceClassName(String sourceClassName) {
        this.sourceClassName = sourceClassName;
    }
}
